import os
from langchain_community.chat_models import ChatZhipuAI 
from dotenv import load_dotenv, find_dotenv
from langchain_core.output_parsers import StrOutputParser
from langchain_core.output_parsers.list import (
    CommaSeparatedListOutputParser
)

_ = load_dotenv(find_dotenv())
model = os.environ.get('model')
if model is None:
    raise ValueError("model is not set in the .env file")

llm = ChatZhipuAI(model=model,
                  temperature=0.9,              
    )

response = llm.invoke(
    "请列出五种富含维生素C的水果名称，以逗号分隔名称，不要出现其他任何字符。"
    )

strResult = StrOutputParser()
result = strResult.invoke(response)
print(result)

listResult = CommaSeparatedListOutputParser()
result= listResult.invoke(response)
print(result)